/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.androball_manager;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.example.database.OpenDB;
import com.example.database.getYourTeam;

public class FirstMenuActivity extends Activity {

	OpenDB db;
	public static String selected_team;
	public static int gameday = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_first_menu);

		// Shows your team and players
		db = new OpenDB(this.getApplicationContext());
		TextView team_name = (TextView) findViewById(R.id.firstMenuChoosePlayer);
		TextView players = (TextView) findViewById(R.id.firstMenuContent);
		players.setMovementMethod(new ScrollingMovementMethod());
		getYourTeam get = new getYourTeam(team_name, players, db);
		get.execute(db);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.first_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * play your gameday
	 */
	public void go_to_WeekMatches(View view) {

		if (gameday < 38) {
			// Play
			Intent intent = new Intent(this, WeekMatchesActivity.class);
			intent.putExtra("GAME", selected_team);
			intent.putExtra("GAMEDAY", gameday);
			startActivity(intent);

		} else
			// Shows league finish message
			alert();
	}

	/**
	 * go to the Liga Table
	 * 
	 * @param view
	 */
	public void go_to_LeaderBoard(View view) {
		Intent intent = new Intent(this, LeaderboardActivity.class);
		startActivity(intent);
	}

	/**
	 * go to the Gameplan
	 */
	public void go_to_Calendar(View view) {
		Intent intent = new Intent(this, CalendarActivity.class);
		startActivity(intent);
	}

	public void alert() {

		new AlertDialog.Builder(this)
				.setTitle(R.string.title_2)
				.setMessage(R.string.message_2)
				.setPositiveButton(android.R.string.ok,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int which) {

							}
						})

				.setIcon(android.R.drawable.ic_dialog_alert).show();
	}
}
